package com.zhihuishu.treenity.controller.operation;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import com.zhihuishu.treenity.consts.Constants;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.able.commons.dto.BaseVideoDto;
import com.able.commons.httpinvoker.IFileCommonsInvoker;
import com.able.livecourse.rmi.dto.ResponseModule;
import com.able.livecourse.rmi.service.LiveCourseRmiService;
import com.able.openapi.overseas.dto.RecruitStudyInfoTreenityDto;
import com.able.openapi.overseas.dto.TeachingTaskDto;
import com.able.openapi.overseas.dto.TreenityPostActiveNumDto;
import com.able.openapi.overseas.dto.TreenityStuActiveNumDto;
import com.zhihuishu.remote.RemoteException;
import com.zhihuishu.toolkit.log.MDCInfoBuilder;
import com.zhihuishu.treenity.controller.BaseController;
import com.zhihuishu.treenity.dto.StuActiveNumDto;
import com.zhihuishu.treenity.dto.VideoinfoDto;
import com.zhihuishu.treenity.service.operation.RunhomeService;
import com.zhihuishu.treenity.util.CopyObjUtils;
import com.zhihuishu.user.openapi.common.dto.UserOpenDto;
import com.zhihuishu.user.openapi.wrapper.ResultWrapper;
import com.zhihuishu.user.openapi.common.UserQueryOpenService;
import org.apache.commons.lang3.StringUtils;

@Controller
@RequestMapping("/operation/runhome")
public class RunhomeController extends BaseController{
	
	@Resource
	private RunhomeService runhomeService;
	@Resource
	private UserQueryOpenService userQueryOpenService;
	@Resource
	private IFileCommonsInvoker iFileCommonsInvoker;
    @Resource
    private LiveCourseRmiService treenityLiveCourseRmiService;
	@ResponseBody
	@RequestMapping("")
	private ModelAndView toSecondStep(Long courseId,HttpServletRequest request) throws RemoteException {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("/operation/runhome");
		if(this.isLoginUserByCourseId(mav, courseId, request.getSession())){
			return mav;
		}
		return mav;
	}
	@ResponseBody
	@RequestMapping(value = "/findRecruitStudyInfo", method = RequestMethod.POST)
	public RecruitStudyInfoTreenityDto findRecruitStudyInfo(Integer recruitId){
			 RecruitStudyInfoTreenityDto recruitStudyInfoTreenityDto=runhomeService.findRecruitStudyInfo(recruitId);
		return recruitStudyInfoTreenityDto;
	}
	@ResponseBody
	@RequestMapping(value = "/findTeachingTaskList", method = RequestMethod.POST)
	public List<VideoinfoDto> findTeachingTaskList(Integer recruitId){
		
		List<VideoinfoDto> videoinfoDtos=new ArrayList<VideoinfoDto>();
		try {
			videoinfoDtos = runhomeService.findTeachingTaskList(recruitId);
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		
		return videoinfoDtos;
	}
	@ResponseBody
	@RequestMapping(value = "/findforums", method = RequestMethod.GET)
	public Map<Object, Object> findforum(Integer recruitId){
		
		Map<Object, Object> map=new HashMap<Object, Object>();
		try {
			map = runhomeService.findforum(recruitId);
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		
		return map;
	}
	@ResponseBody
	@RequestMapping(value = "/runExe", method = RequestMethod.POST)
	public Map<String,Object> runExe(int liveCourseId,int type){
		Map<String,Object> zoomInfo=null;
		Long userId = Long.parseLong(getLoginUID().toString());
		try {
			zoomInfo=runhomeService.runExe(liveCourseId, type, userId);
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		return zoomInfo;
		
	}
	
}